<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<div class="modal-dialog ms-modal-dialog" style="width: 550px;">
  <div class="modal-content">
     
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
      <h4 class="modal-title">新建专属供应商用户</h4>
    </div>
    
    <form class="form-horizontal ms-form form-personal-info" method="POST" action="${ctx.host}/fms-users" data-validate="true">

     <div class="modal-body">
     
       <div class="form-group  ms-form-group">
          <label class="control-label col-xs-3"><span class="text-red">*</span>登录名：</label>
          <div class="col-xs-8 pull-left role-login-name">
            <input type="text" class="form-control" name="loginName" data-validate="required" placeholder="登录名" tabindex="1" autocomplete="off"/>
          </div>
        </div>
        
        <div class="form-group  ms-form-group">
          <label class="control-label col-xs-3"><span class="text-red">*</span>角色：</label>
          <div class="col-xs-8">
            <select class="select2 form-control" name="authority" tabindex="2" data-validate="required"> 
              <option></option>
              <c:forEach items="${roles}" var="role">
                <option value="${role.code}">${role.name}</option>
              </c:forEach>
            </select>
          </div>
        </div>
        
        <div class="form-group ms-form-group fms-user">
          <label class="control-label col-xs-3"><span class="text-red">*</span>专属供应商：</label>
          <div class="col-xs-8">
            <select class="select2 form-control" name="orgId" tabindex="3" data-validate="required"> 
              <option></option>
              <c:forEach items="${organizations}" var="organization">
                <option value="${organization.id}">${organization.name}</option>
              </c:forEach>
            </select>
          </div>
        </div>
        
        <div class="form-group  ms-form-group">
          <label class="control-label col-xs-3"><span class="text-red">*</span>姓名：</label>
          <div class="col-xs-8">
            <input type="text" class="form-control" name="name" data-validate="required" tabindex="4" placeholder="姓名" autocomplete="off"/>
          </div>
        </div>
        
        <div class="form-group  ms-form-group">
          <label class="control-label col-xs-3"><span class="text-red">*</span>密码：</label>
          <div class="col-xs-8">
            <input type="password" class="form-control" name="password" data-validate="required" tabindex="5" placeholder="请输入密码" autocomplete="off"/>
          </div>
        </div>
        
        <div class="form-group  ms-form-group">
          <label class="control-label col-xs-3">性别：</label>
          <div class="col-xs-8">
            <select class="select2 form-control" name="gender" tabindex="5"> 
              <option value="男">男</option>
              <option value="女">女</option>
            </select>
          </div>
        </div>
        
        <div class="form-group  ms-form-group vam-user" style="display: none;">
          <label class="control-label col-xs-3">座机号码：</label>
          <div class="col-xs-8">
            <input type="text" class="form-control" name="phone" data-validate="phone" tabindex="5" placeholder="请输入座机号码" autocomplete="off"/>
          </div>
        </div>
        
        <div class="form-group  ms-form-group vam-user" style="display: none;">
          <label class="control-label col-xs-3">手机号码：</label>
          <div class="col-xs-8">
            <input type="text" class="form-control" name="mobile" data-validate="mobile" tabindex="5" placeholder="请输入手机号码" autocomplete="off"/>
          </div>
        </div>
        
        <div class="form-group  ms-form-group vam-user" style="display: none;">
          <label class="control-label col-xs-3">电子邮箱：</label>
          <div class="col-xs-8">
            <input type="text" class="form-control" name="email" data-validate="email" tabindex="5" placeholder="请输入电子邮箱" autocomplete="off"/>
          </div>
        </div>
        
        <div class="form-group  ms-form-group vam-user" style="display: none;">
          <label class="control-label col-xs-3"><span class="text-red">*</span>所属部门：</label>
          <div class="col-xs-8">
            <select class="select2 form-control" name="departmentId" tabindex="5">
              <option value=""></option>
              <c:forEach var="department" items="${departments}">
                <c:choose>
                  <c:when test="${not empty department.parentDesc}">
                    <option value="${department.id}" data-org="${department.orgId}">${department.parentDesc}&nbsp;-&nbsp;${department.desc}</option>                    
                  </c:when>
                  <c:otherwise>
                    <option value="${department.id}" data-org="${department.orgId}">${department.desc}</option>
                  </c:otherwise>
                </c:choose>
              </c:forEach>
            </select>
          </div>
          <input type="hidden" name="departmentName">
        </div>
      </div>
      
      <div class="modal-footer ms-modal-footer">
        <button type="submit" class="btn ms-btn btn-primary">确定</button>
        <button type="button" class="btn ms-btn ms-btn-gary" data-dismiss="modal">取消</button>
      </div>

    </form>
    
  </div>
</div>

<script type="text/javascript">
$(document).ready(function(){
  
  $('select[name="authority"]').select2({
    theme: "classic",
    placeholder : '请选择角色',
    minimumResultsForSearch : -1,
    allowClear : true,
  });
  
  $('select[name="orgId"]').select2({
    theme: "classic",
    placeholder : '请选择专属供应商',
    minimumResultsForSearch : 5,
    allowClear : true,
  });
  
  $('select[name="gender"]').select2({
    theme: "classic",
    placeholder : '请选择性别',
    minimumResultsForSearch : -1,
    allowClear : true,
  });
  
  $('select[name="departmentId"]').select2({
    theme: "classic",
    placeholder : '请选择',
    minimumResultsForSearch : -1,
    allowClear : true
  });
  
})
</script>